home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Toolbox / Toolbox.h < prev   
Encoding:
C/C++ Source or Header  |  1998-06-07  |  4.0 KB  |  161 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ToolboxModules.h
  3.  
  4.     Contains:    stuff
  5.  
  6. */
  7.  
  8. #ifndef _TOOLBOXMODULES_
  9. #define _TOOLBOXMODULES_
  10. #pragma once
  11.  
  12. #ifndef __MODULE__
  13. #include "Module.h"
  14. #endif
  15.  
  16. #include <Windows.h>
  17.  
  18. #if GENERATINGCFM
  19.  
  20.     #include <CodeFragments.h>
  21.     
  22.     inline bool HasCFMSymbol(void *proc)    { return proc != (void*) kUnresolvedCFragSymbolAddress;    }
  23. #else
  24.  
  25.     // this must be done as a macro or it won't compile
  26.  
  27.     #define HasCFMSymbol(proc)    true
  28.  
  29. #endif
  30.  
  31.  
  32. //--------------------------------------------------------------------------------
  33. class ApplicationHeap : public TModule
  34. {
  35.     DeclareClassSingle(ApplicationHeap, TModule);
  36.  
  37. private:
  38.     static ApplicationHeap*    gApplicationHeap;
  39.  
  40.     unsigned long            fInitialized : 1;
  41.     unsigned long            fStackSize     : 31;
  42.     
  43. public:
  44.     ApplicationHeap(long stackSize = 0);
  45.     virtual ~ApplicationHeap();
  46.  
  47.     virtual void    Initialize(void);    // Do your thing
  48.     virtual bool    Initialized(void);    
  49.  
  50.     static ApplicationHeap&    GetApplicationHeap();
  51. };
  52.  
  53. //--------------------------------------------------------------------------------
  54. class Toolbox : public TModule
  55. {
  56.     DeclareClassSingle(Toolbox, TModule);
  57.  
  58. private:
  59.     static Toolbox*            gToolbox;
  60.     static bool                gInitialized;
  61.     static bool                gCanInteract;                
  62.     static bool                gHasThreads;
  63.  
  64. public:
  65.     Toolbox();
  66.     virtual ~Toolbox();
  67.  
  68.     virtual bool    Validate(void);
  69.     virtual void    Initialize(void);    // Do your thing
  70.     virtual bool    Initialized(void);    
  71.  
  72.     static Toolbox&    GetToolbox();
  73.     
  74.     inline bool        CanInterract()                { return gCanInteract;    }
  75.     inline bool        HasWindowMgr()                { return gCanInteract;    }
  76.     inline bool        HasThreads()                { return gHasThreads;    }
  77.  
  78.     static bool        HasGestalt(OSType selector, long mask = 0);
  79.     static bool        HasSymbol(void *proc)        { return proc != nil;    }
  80.     
  81.     static short    FindWindow(Point where, WindowPtr& win);
  82. };
  83.  
  84. //--------------------------------------------------------------------------------
  85. #define FatalErrorAlert(list, string)  {}
  86.  
  87. #if CFMSYSTEMCALLS
  88.     // Use this macro for an entry point to a system library which may be a trap
  89.     // or a CFM library entry point. Noter that we use CFMSYSTEMCALLS instead of
  90.     // GENERATINGCFM here because the Thread we want to be exactly in sync with
  91.     // the existance of the nWORDINLINE macro.
  92.  
  93.     #define ENTRYPOINT(x)    ((ProcPtr)(x))
  94. #else
  95.     #define ENTRYPOINT(x)    nil
  96. #endif
  97.  
  98.  
  99. //--------------------------------------------------------------------------------
  100. // an abstract base class for a manager which can be tested for with a 
  101. // Gestalt selector. 
  102. class ToolboxManager : public TModule
  103. {
  104.     DeclareClassSingleAbstract(ToolboxManager, TModule);
  105.  
  106.     OSType            fGestaltSelector;    
  107.     long            fGestaltValue;
  108.  
  109. #if GENERATINGCFM
  110.     ProcPtr            fLibraryEntry;
  111. #endif
  112.  
  113.     unsigned long    fRequired            : 1;    // This manager is required for validate step
  114.     unsigned long    fAvailable            : 1;    // This manager is available
  115.  
  116.     unsigned long    fInitializeCalled    : 1;    // We've tried to initialize the manager
  117.     unsigned long    fInitialized        : 1;    // It is initialized
  118.  
  119.     unsigned long    fLibraryChecked        : 1;    // We've checked for the shared library
  120.     unsigned long    fLibraryPresent        : 1;    // It's present
  121.     unsigned long    fLibraryRequired    : 1;    // Library must b present
  122.  
  123.     unsigned long    fGestaltCalled        : 1;    // Gestalt has been called
  124.     unsigned long    fGestaltValid        : 1;    // Gestalt returned noErr
  125.     unsigned long    fGestaltRequired    : 1;    // Bit below must be set
  126.     unsigned long    fGestaltBit            : 5;    // Bit to test for presense    
  127.  
  128. public:
  129.     ToolboxManager(OSType gestaltSelector, short gestaltBit = 0, 
  130.                     ProcPtr entryPoint = nil, bool required = false);
  131.  
  132. protected:
  133.     void RuntimeCheck(void);
  134.  
  135.     virtual bool    Validate(void);        // Check against system, possibly re-order
  136.     virtual bool    Initialized(void);    
  137.     virtual bool    InitializeCalled(void);    
  138.     virtual void    Initialize(void);    // Do your thing
  139.  
  140.     virtual void DoInitialization(void);
  141. };
  142.  
  143. //--------------------------------------------------------------------------------
  144.  
  145. #if !qDebug
  146.  
  147. inline ApplicationHeap&    ApplicationHeap::GetApplicationHeap()
  148. {
  149.     return *gApplicationHeap;
  150. }
  151.  
  152. inline Toolbox& Toolbox::GetToolbox()
  153. {
  154.     return *gToolbox;
  155. }
  156.  
  157. #endif
  158.  
  159.  
  160. #endif // _TOOLBOXMODULES_
  161.